define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search', 'shiftform', 'modalSearch',
        'datetimepicker', 'datetimepickerCN'],
function($, validate) {
  return {
    
    init: function() {
      this.initPage();
      this.initEmployee();
      this.triggerModalSearch();
    },
    
    initPage: function(){
        
      $(document).find('form').bt_validate();
      
      $('select[name="organizationId"]').select2({
        theme: "classic",
        placeholder : '请选择',
        minimumResultsForSearch : -1,
        allowClear : true,
      });
      
      $('.date').datetimepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        language: 'zh-CN',
        todayBtn: 'linked',
        startDate: '${today}',
        todayHighlight: true,
        pickerPosition: 'bottom-right',
        minView: 'month'
      });
      
    },
    
    initEmployee:function() {
        
      var choseEmployees = {
         url: function(){
            var url = window.__CTX__.root + '/employees/query';
            return url + "?companyIds=" + $("[name='organizationId']").val();
         },
         tableColumns: ['员工代码', '员工名称'],
         tableValues: ['code', 'name'],
         displayValues: ['code', 'name'],
         values: ['id']
      }
      $('[data-target="#modal-search-eId"]').modalsearch(choseEmployees);
      
      var options = {
        time: 1000,
        url: window.__CTX__.root + "/employees/query",
        queryName: "code",
        value: ["id"],
        display: ["code", "name"]
      }
      $('.eId-search').koalaSearch(options);
        
    },
    
    triggerModalSearch: function() {
      $('.modal-search').each(function() {
        var value = $(this).val();
        console.info(value);
        if (value) {
          $(this).trigger('blur');
        }
      });
    }
    
  }
})